home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / gateway.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  5KB  |  222 lines

  1. #include    "multix.h"
  2.  
  3. #include    <stdio.h>
  4. #include    <stdlib.h>
  5.  
  6. #include    <string.h>
  7. #include    <time.h>
  8.  
  9.  
  10. #include    "appl.h"
  11. TMdxProcId        MyId;
  12.  
  13. void    ApplReplyWithTime(
  14. TMdxSRMsgInfo  *MsgInfo
  15. )
  16. {
  17.     TMdxTime    CurrTime;
  18.     TMdxError    Result;
  19.     CurrTime    =    MdxGetTime();
  20.     Result =    MdxReplyWithData(    MsgInfo,                /*    Original Msg    */
  21.                             MdErrNoError,            /*    No Error Reply    */
  22.                             (UInt8Ptr)&CurrTime,    /*    Data            */
  23.                             sizeof(CurrTime),        /*    Data Size        */
  24.                             ApplGetTimeReplyCode,    /*    Msg Code        */
  25.                             0,                        /*    Priority        */
  26.                             MdxSendReliable,        /*    Send Attributes    */
  27.                                                     /*    Success/Failure    */
  28.                                                     /*    Report            */
  29.                             0,                        /*    No ReqSeq        */
  30.                             1000                    /*    10 Secs    Timeout    */
  31.                             );
  32.     printf("Sending Time : Result = %d\n",Result);
  33. }
  34.  
  35.  
  36. void    ApplNewMsgReceived(
  37. TMdxEvent    *Event
  38. )
  39. {
  40.     TMdxSRMsgInfo    *MsgInfo;
  41.  
  42.     /*
  43.     "Event->Data"    holds the information abount the new message.
  44.     */
  45.  
  46.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  47.  
  48.     /*    First    thing is to check MsgCode of the new message    */
  49.  
  50.     switch(MsgInfo->Received.MsgCode)
  51.     {
  52.         case    ApplGetTimeMsgCode    :
  53.         {
  54.             ApplReplyWithTime(MsgInfo);
  55.         }
  56.         break;
  57.     }
  58. }
  59.  
  60.  
  61. void    ApplTimerEvent(
  62. TMdxEvent    *Event
  63. )
  64. {
  65.     TMdxApplTimerInfo    TimerInfo;
  66.  
  67.     /*
  68.     "Event->Data"    holds the information abount the timer.
  69.     We use    "MdxGetApplTimerInfo()" to extract that info.
  70.     */
  71.  
  72.     MdxGetApplTimerInfo(Event->Data,&TimerInfo);
  73.  
  74.     switch(TimerInfo.Code)
  75.     {
  76.         case    ApplTimerDisplayTimer    :
  77.         {
  78.             time_t    Time    =    time(NullP);
  79.             printf("Current Time Is : %s",ctime(&Time));
  80.         }
  81.         break;
  82.         default :    break;
  83.     }
  84. }
  85.  
  86.  
  87.  
  88. void    ApplInitReceived(void)
  89. {
  90.     /*
  91.     You may choose to use onw or more links of the types specified.
  92.     Un comment the relevent "MdxOpenLink()".
  93.  
  94.     You may change the parameters for the links.
  95.     */
  96.  
  97.  
  98.     TMdxLinkParams    LinkParams;
  99.     memset(&LinkParams,0,sizeof(LinkParams));
  100.     strcpy(LinkParams.LinkName.Byte,"com2");
  101.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  102.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  103.     LinkParams.ConnectTimeout        =    0x7fffffff;
  104.     LinkParams.MaxConnectRetries    =    -1;
  105.     LinkParams.ConnectRetriesDelay    =    200;
  106.     LinkParams.LinkBaud             =    19200;
  107.     LinkParams.UseDlcFraming        =    True;
  108.     LinkParams.ImAliveInterval        =    400l;
  109.     LinkParams.MaxPollRetries        =    2;
  110.     LinkParams.L1MaxSendSize        =    256;
  111.     /*
  112.     MdxOpenLink(&LinkParams);
  113.     */
  114.     memset(&LinkParams,0,sizeof(LinkParams));
  115.     strcpy(LinkParams.LinkName.Byte,"MdxGateway");
  116.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  117.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  118.     LinkParams.ConnectTimeout        =    1000;
  119.     LinkParams.MaxConnectRetries    =    -1;
  120.     LinkParams.ConnectRetriesDelay    =    200;
  121.     LinkParams.UseDlcFraming        =    True;
  122.     LinkParams.MaxPollRetries        =    10;
  123.     LinkParams.L1MaxSendSize        =    500;
  124.     /*
  125.     MdxOpenLink(&LinkParams);
  126.     */
  127.  
  128.     memset(&LinkParams,0,sizeof(LinkParams));
  129.     strcpy(LinkParams.LinkName.Byte,"MdxGateway");
  130.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  131.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  132.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  133.     LinkParams.ConnectRetriesDelay    =    300l;
  134.     LinkParams.L1MaxSendSize        =    1024;
  135.     LinkParams.MaxConnectRetries    =    -1l;
  136.     /*
  137.     MdxOpenLink(&LinkParams);
  138.     */
  139.     MdxSetApplTimer(ApplTimerDisplayTimer,6000,0,0,0,-1);
  140. }
  141.  
  142.  
  143. void    cdecl    ApplEventHandler(
  144. TMdxEvent    *Event
  145. )
  146. {
  147.     switch(Event->Code)
  148.     {
  149.         case    MdxEventApplInit                :
  150.         {
  151.             ApplInitReceived();
  152.         }
  153.         break;
  154.         case    MdxTimerEvent                    :
  155.         {
  156.             ApplTimerEvent(Event);
  157.         }
  158.         break;
  159.         case    MdxStdInAvailable                :
  160.         {
  161.             ApplShutdown    =    True;
  162.         }
  163.         break;
  164.         case    MdxEvProcessAdded        :
  165.         {
  166.             printf("Process Found = %s  (%ld)\n",Event->Data,Event->ProcId);
  167.         }
  168.         break;
  169.         case    MdxEvProcessRemoved            :
  170.         {
  171.             printf("Process Lost = %s  (%ld)\n",Event->Data,Event->ProcId);
  172.         }
  173.         break;
  174.         case    MdxEvLinkStatus        :
  175.         {
  176.             printf("Link %s , Status = %d\n",((TMdxLinkParams    *)Event->Data)->LinkName.Byte,Event->Error);
  177.         }
  178.         break;
  179.         case    MdxEvCallReqReceived        :
  180.         {
  181.             MdxAcceptProcess(Event->ProcId,(void *)0);
  182.         }
  183.         break;
  184.         case    MdxEvDataMsgReceived        :
  185.         {
  186.             ApplNewMsgReceived(Event);
  187.         }
  188.         break;
  189.         default                                 :    break;
  190.     }
  191. }
  192.  
  193.  
  194. Int cdecl    main(
  195. Int     Argc,
  196. Int8Ptr *Argv
  197. )
  198. {
  199.  
  200.     InitStack    =    &Argc;
  201.     if (    Argc    <    2    )
  202.     {
  203.         printf("Usage : GateWay <Proccess Id>\n");
  204.         return(5);
  205.     }
  206.     MyId    =    (TMdxProcId)atol(Argv[1]);
  207.     if (    MyId    <=    0    )
  208.     {
  209.         printf("Node Id Should be between 1 - %ld\n",0x7fffffffl);
  210.         return(0);
  211.     }
  212.  
  213.     MultiXStart(MyId,"MultiX Gateway",-1,ApplEventHandler);
  214.  
  215.     printf("Type any key to stop the program...\n");
  216.     while (    ApplShutdown    ==    False    )
  217.     {
  218.         MultiXWaitEvent();
  219.     }
  220.     return(0);
  221. }
  222.